Add additional guardrails against unsigned underflows caused by wrong WordCount#3787
Conversation
There was a problem hiding this comment.
Is the vulnerability exposed only for text SPIR-V form or for binary form as well?
I feel like that the fix is built under an assumption, that the 1st Word of the instruction is the OpCode. It's not. The first Word is OpCode plus the instruction's words count (16 bits each for a 32-bit word). Should we be checking, that the encoded word count is legit instead (per each instruction) (I kinda feel, that llvm-spirv is already doing that).
It's exposed for both formats.
I don't think the fix assumes that. The core of the fix is and the rest is just making sure that |
|
@maarquitos14 please address CI complaints. #3840 should be merged first to avoid translation time regression. @vmaksimo @svenvh @YuriPlyakhin please take a look. While I do believe, that the better approach is to enforce spirv-val before consuming SPIR-V module, yet the issue this PR addresses is real as underflow can cause CWE-789. I'll check what would be the cost of enabling spirv-val as optional validation layer be llvm-spirv (probably we would need some customizations). |
Following up on #3671, this adds additional guardrails for cases that were still unhandled by the previous patch. This PR also includes multiple new tests for invalid wordcounts, and joins them all --the new, and the ones added by #3671-- in their own directory (test/negative/invalid-wordcount).